package com.three.Controller;

import com.github.pagehelper.PageInfo;
import com.three.Pojo.Collage;
import com.three.Service.ICollageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/collage")
public class CollageController {
    @Autowired
    private ICollageService collageService;
    //1.跳转学院管理页面
    @RequestMapping("/tocollage.do")
    public String findAll(ModelMap map, String collageName,
                          @RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = "5") Integer pageSize){
        PageInfo<Collage> pagelist=collageService.findlist(pageNum,pageSize,collageName);
        map.addAttribute("pagelist",pagelist);
        map.addAttribute("collageName",collageName);
        return "collage";
    }
    //2..学院添加页面跳转
    @RequestMapping("/toadd.do")
    public String toadd(){
        return "collageAdd";
    }
    //3..学院添加数据保存
    @RequestMapping("/addsave.do")
    public String addsave(Collage collage){
        collageService.addsave(collage);
        return "redirect:/collage/tocollage.do";
     }
    //4.学院预修改
    @RequestMapping("/promodify.do")
    public String toupdate(Integer Id, ModelMap map){
        Collage collage=collageService.findByid(Id);
        map.addAttribute("collage",collage);
        return "collageUpdate";
    }
    //5.学院修改保存
    @RequestMapping("/updatesave.do")
    public  String updatesave(Collage collage){
        collageService.updatesave(collage);
        return "redirect:/collage/tocollage.do";
    }
    //6.学院删除
    @RequestMapping("/delete.do")
    public  String delete(Integer Id){
        collageService.delete(Id);
        return "redirect:/collage/tocollage.do";
    }
}
